package com.md.threadtest.jieli;

/**
 * @Author Gong
 * @Description
 * @dATE 2022/3/29 11:58
 **/
public class RunQuan implements Runnable {
    private  int count = 1000;
    int x = 0;
    @Override
    public void run() {
        synchronized (this) {
            while (count > 0) {
                try {
                    Thread.sleep(500); //模拟跑步延时
                } catch (InterruptedException e) {
                    System.out.println("网络位置异常");
                }
                count -= 10;
                x += 10;
                System.out.println(
                        Thread.currentThread().getName()+"跑了"+x+"米");
                if(x % 100 == 0){
                    break;
                }
            }
        }
    }

    public static void main(String[] args) {
        RunQuan rq = new RunQuan();
        for (int i = 1; i <= 10; i++) {
            Thread th = new Thread(rq);
            th.setName("选手"+i);
            th.start();

        }
    }
}
